package java67_18;

public class Caculator {
	private String brand;

	public Caculator(String brand) {
		super();
		this.brand = brand;
	}
//返回0的时候,让人疑惑
//	public int divide(int a, int b) {
//		try {
//			int c = a / b;
//			return c;
//		} catch (Exception e) {
//			System.out.println("除法错误");
//			e.printStackTrace();
//		}
//		return 0;
//	}

	public int divide(int a, int b) {
		try {
			int c = a / b;
			return c;
		} catch (Exception e) {
			System.out.println("除法错误");
			// e.printStackTrace();
			throw e;// 方法结束了
		}
		// return 0;// 这行有错
	}

	// 提醒:此方法会出异常
	public int div(int a, int b) throws Exception {
		try {
			int c = a / b;
			return c;
		} catch (Exception e) {
			System.out.println("除法错误");
			throw new Exception("除零错误", e);
		}

	}

	@Override
	public String toString() {
		return brand + "计算器";
	}
}
